<?php

/*
 * 洗牌算法
 */
function washCard($array){
    $cardNum = count($array);
    for($i= $cardNum - 1; $i>0; $i--){
        //随机数生成器，范围[0, i]
        $rand = mt_rand(0, $i);

        $temp = $array[$i];
        $array[$i] = $array[$rand];
        $array[$rand] = $temp;
    }
    return $array;
}

function getSpecsModelBrand($str){
    //$str = '九阳 （PADOOR） 电烤箱 KX32-J12 550 * 415 * 420mm';
    //$str = '派的（PADOOR）欧式简约实木复合YA-004油漆门卧室门室内门';

    $model = '';    //型号    KX32-J12
    $specs = '';    //规格    550 * 415 * 420mm
    $brand = '';

    //找规格   eg: 550 * 415 * 420mm
    $isMatched = preg_match('/(?<=[^\w])((\d+)(\*|\s|M|m)+){2,3}/', $str, $matches);
    if($isMatched){
        $specs = $matches[0];
    }
    $strNew = str_replace($specs, '', $str);    //替换掉规格     九阳  电烤箱 KX32-J12

    //找品牌   eg: （PADOOR）
    $isMatchesBrand = preg_match('/(（|\().*(）|\))/', $strNew, $matchesBrand);
    if($isMatchesBrand){
        $brand = $matchesBrand[0];
    }
    $strNew = str_replace($brand, '', $strNew);

    //找型号   eg: KX32-J12
    $isMatched2 = preg_match('/(\w+-?\w+)/', $strNew, $matches2);
    if($isMatched2){
        $model = $matches2[0];
    }
    $strNew = str_replace($model, '', $strNew);


    return [
        'model' => $model,
        'specs' => $specs,
//        'guige' => $specs,
        'brand' => $brand,
        'name' => $str,
        'rubbish' => $strNew,
    ];
}
$str = '九阳 （PADOOR） 电烤箱 KX32-J12 550 * 415 * 420mm';
//$str = '派的（PADOOR）欧式简约实木复合YA-004油漆门卧室门室内门';
var_dump($str);
var_dump('<br><br>');
$data = getSpecsModelBrand($str);
var_dump($data);



exit();
